package org.loofer.uiframework.helper;

import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import org.loofer.uikit.StateView;
import org.loofer.uikit.StateView.OnConfigStateViewListener;
import org.loofer.uikit.StateView.State;

public class StateViewHelper {
    private OnConfigStateViewListener mDefaultConfig = new OnConfigStateViewListener() {
        public void onConfigStateView(View view, State state) {
            if (State.FAILED.equals(state)) {
                view.setOnClickListener(StateViewHelper.this.mOnRetryClickListener);
            }
        }
    };
    private OnClickListener mOnRetryClickListener;

    public StateView inject(View view, OnClickListener onRetryClickListener) {
        this.mOnRetryClickListener = onRetryClickListener;
        StateView stateView = new StateView(view.getContext());
        stateView.setStateProperty(State.FAILED, 2130903084);
        stateView.setStateProperty(State.LOADING, 2130903085);
        stateView.setStateProperty(State.NO_DATA, 2130903086);
        stateView.setStateProperty(State.SUCCESS, view);
        stateView.setOnConfigStateViewListener(this.mDefaultConfig);
        stateView.setLayoutParams(new LayoutParams(-1, -1));
        return stateView;
    }
}
